package com.itheima.dao.impl;

import com.itheima.dao.AccountDao;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;


/**
 *@Repository dao层的注解
 * */
@Repository
public class AccountDaoImpl implements AccountDao {

    @Autowired //注入queryRunner
    private QueryRunner queryRunner;
    @Override
    public void out(String outName, int money) throws SQLException {
        System.out.println("转出");
        String sql = "update  tal_account set money=money-? where username=? ";
        Object [] params = { money ,  outName };
        int count = queryRunner.update(sql, params);
        System.out.println(count);

    }

    @Override
    public void in(String inName, int money) throws SQLException {
        System.out.println("转入");
        String sql = "update  tal_account set money=money+? where username=? ";
        Object [] params = { money ,  inName };
        int count = queryRunner.update(sql, params);
        System.out.println(count);
    }
}
